package cs575.wido.ui;
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.BoxLayout;
import javax.swing.JOptionPane;

import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import cs575.wido.User;
import cs575.wido.action.GroupAction;
import cs575.wido.action.LogoutAction;
import cs575.wido.action.TaskAction;
import cs575.wido.action.UserAccountAction;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.Icon;
import javax.swing.ImageIcon;


public class HomeWindow extends JFrame {

	private JPanel contentPane;
	private JMenuBar menuBar;
	private JMenu mnHelp;
	private JMenuItem mntmAbout;
	private JButton btnTask;
	private JLabel lblSelectYourAction;
	private JButton btnGroup;
	private JButton btnAccount;
	private JButton btnLogOut;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					HomeWindow frame = new HomeWindow();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public HomeWindow() {
		setTitle("WiDo");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 200, 300);
		
		menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		mnHelp = new JMenu("Help");
		menuBar.add(mnHelp);
		
		mntmAbout = new JMenuItem("About WiDo");

		mnHelp.add(mntmAbout);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new GridLayout(0, 1, 0, 0));
		
		lblSelectYourAction = new JLabel("Select your Action");
		lblSelectYourAction.setHorizontalAlignment(SwingConstants.CENTER);
		contentPane.add(lblSelectYourAction);
		
		btnTask = new JButton("Task");
		contentPane.add(btnTask);
		
		btnGroup = new JButton("Group");
		contentPane.add(btnGroup);
		
		btnAccount = new JButton("Account");
		contentPane.add(btnAccount);
		
		btnLogOut = new JButton("Log Out");
		contentPane.add(btnLogOut);
		
		buildActions();
	}
	
	private void buildActions() {
		btnTask.setAction(new TaskAction());
		btnGroup.setAction(new GroupAction());
		// TODO get User from here
		User user = new User();
		btnAccount.setAction(new UserAccountAction(user));
		btnLogOut.setAction(new LogoutAction(this));
		
		mntmAbout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String message = "WiDo is created by a group of enthusiastic students\n" +
						"Bander Alsulami\n" +
						"Kevin Cheung\n" +
						"Zdravko Tyankov\n" +
						"Lu Xiao";
				Icon icon = new ImageIcon("logo.png");
				//JOptionPane.showMessageDialog(HomeWindow.this, message);
				JOptionPane.showMessageDialog(HomeWindow.this, message, "About", JOptionPane.DEFAULT_OPTION, icon);
			}
		});
	}

}
